//npm install babel-register babel-preset-env -D 解决node不支持 import export
require('babel-register')({
    presets: ['env']
})

const fs = require('fs');
const path = require('path');
const express = require('express');
const app = express();
const bodyParser = require("body-parser");
const router = require("./route/templateCode.ts")

app.use(express.static(path.resolve(__dirname, '../dist')))
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json())

app.get('/sw/*', function (req, res) {
    const html = fs.readFileSync(path.resolve(__dirname, '../dist/index.html'), 'utf-8')
    res.send(html)
})

//代码模板
app.use('/api/templateCode', router)

app.listen(19999, () => {
    const hostname = 'localhost';
    const port = 19999;
    console.log(`Server running at http://${hostname}:${port}/`);
});